import 'dart:io';

import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:hc_bot_pro/common/model/channel.dart';
import 'package:hc_cure_sdk_flutter/model/cure/cure.dart';

import '../common/service/channel/channel.dart';
import '../common/service/therapy_service.dart';

class CureController extends GetxController {
  List<Cure> get cures => Get.find<TherapyService>().cachedCureList;

  Channel? get channel => Get.find<ChannelService>().channel;

  String get bgUrl =>
      Get.find<ChannelService>().channel?.appStyle.appHomeBackImage ?? "";

  CureController();

  _initData() {}

  void onRefreshData() {
    refreshCures();
  }

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }

  Future refreshCures() async {
    try {
      if (cures.isEmpty) {
        Get.find<TherapyService>().refreshTherapyList();
      }
      update(["cure"]);
    } catch (e) {
      EasyLoading.showError(e.toString());
    }
  }
}
